package com.liziba.trend.controller;

import com.liziba.trend.api.IndexData;
import com.liziba.trend.config.IpConfiguration;
import com.liziba.trend.entity.Result;
import com.liziba.trend.entity.StatusCode;
import com.liziba.trend.service.IndexDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: trend
 * @description: 获取指定基金代码的基金数据
 * @author: liziba
 * @date: 2021-02-03 11:22
 */

@RestController
@RequestMapping("/indexData")
@CrossOrigin
public class IndexCodeController {

    /**
     * 基金数据获取服务service
     */
    @Autowired
    private IndexDataService indexDataService;

    /**
     * 获取当前服务configuration
     */
    @Autowired
    private IpConfiguration ipConfiguration;

    /**
     * 获取指定基金代码的基金数据
     * @param code          基金代码
     * @return
     * @throws Exception
     */
    @GetMapping("/data/{code}")
    public List<IndexData> get(@PathVariable(value = "code") String code) throws Exception {
        System.out.printf("hello, current instance port is : " + ipConfiguration.getServerPort());
        List<IndexData> indexDataList = indexDataService.get(code);
        return indexDataList;
    }
}
